use std::{cmp::Ordering, io};
use rand::prelude::*;



fn main() {
    println!("猜数!");

    let mut rng = rand::rng();
    let secret_number:u32 = rng.random_range(0..=100);
    

    println!("猜一个数：");
    loop {
        let mut guess = String::new();
        io::stdin().read_line(&mut guess).expect("无法读取行");
        // println!("你猜的数是：{}", guess);
    
        let guess:u32 = match guess.trim().parse() {
            Ok(num) => num,
            Err(_) => {
                println!("Please type a number!");
                continue;
            }
        };
        
        match guess.cmp(&secret_number) {
            Ordering::Less => println!("Too small!"),
            Ordering::Greater => println!("Too big!"),
            Ordering::Equal => {
                println!("You win!");
                break;
            }
        }
    }
}
